#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f;

bool cmp(const pair<int, int>& p1, const pair<int, int>& p2)
{
	return p1.first > p2.first || (p1.first == p2.first && p1.second < p2.second);
}

void solve()
{
	int n, k;
	cin >> n >> k;
	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		x %= k;
		a[i] = { x,i + 1 };
	}
	sort(a.begin(), a.end(), cmp);
	vector<int> ans;
	for (int i = 0; i < n; i++)
		if (a[i].first == 0) ans.push_back(a[i].second);
	for (int i = 0; i < n; i++) if (a[i].first != 0) ans.push_back(a[i].second); else break;
	for (int i = 0; i < n; i++) cout << ans[i] << ' ';
	cout << endl;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	cin >> _;
	while (_--)
	{
		solve();
	}
	return 0;
}